{include file="public/header"/}
{include file="public/navleft"}
<style>
    .laytable-cell-checkbox, .laytable-cell-numbers, .laytable-cell-radio, .laytable-cell-space{
        padding-top: 3px;
    }
</style>
<div class="tpl-content-wrapper">
    <input type="hidden" name="username" id="cdrq" value="{$data[0]['cdrq']|strtotime}"/>
    <input type="hidden" name="username" id="ybbh" value="{$data[0]['ybbh']}"/>
    <input type="hidden" name="username" id="yqdh" value="{$data[0]['yqdh']}"/>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm layui-bg-blue" lay-event="getCheckData">删除选中行</button>
            <button class="layui-btn layui-btn-sm layui-bg-blue" lay-event="getCheckLength"  id="refuse">刷新</button>
            <!--<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
        </div>
    </script>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="del">删除</a>
    </script>
    <table id="demo" lay-filter="demo">
    </table>
    <script>
            layui.use('table', function () {
                var cdrq = $(" #cdrq ").val();
                var ybbh = $(" #ybbh ").val();
                var yqdh = $(" #yqdh ").val();
                var table = layui.table;
                table.render({
                    elem: '#demo'
                    , height: 512
                    , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                    , url: '/index.php/index/report/layEditReportXmcdz/' //数据接口
                    , where: {cdrq: cdrq, ybbh: ybbh, yqdh: yqdh}
                    , request: {
                        cdrq: 'cdrq' //页码的参数名称，默认：page
                        , ybbh: 'ybbh' //每页数据量的参数名，默认：limit
                        , yqdh: 'yqdh'
                    }
                    , cols: [[ //表头
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'xmmc_cn', title: '项目名字', width: 230, sort: true,}
                        , {field: 'xmdh', title: '项目代号', width: 150, sort: true,}
                        /*       ,{field: 'zhdh', title: '组合代号', width: 120, edit:'text'}*/
                        , {field: 'xmcdz', title: '测定值', width: 160, edit: 'text'}
                        , {field: 'dw', title: '单位', width: 160, edit: 'text'}
                        , {field: 'gdbj', title: '高低标记', width: 160, edit: 'text'}
                        , {field: 'ckz', title: '项目参考值', width: 120, edit: 'text'}
                        , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 206}
                    ]]
                });

                //监听工具条
                table.on('tool(demo)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                       console.log(JSON.stringify(data));
                        layer.confirm('确认删除**'+ data.xmmc_cn + '**这个项目吗！', function (index) {
                            // 执行异步请求  $.post
                            layer.load(2);
                            setTimeout(function(){
                                layer.closeAll('loading');
                            }, 1500);
                            var url = 'DelXmcdzByYxyx';
                            $.post(url,data,function(result){
                                if(result.code == 1) {
                                    layer.msg(result.msg);
                                }
                                if(result.status == 0) {
                                    layer.msg(result.msg);
                                }
                            },'JSON');
                            obj.del();
                            layer.close(index);
                        });
                    } else if (obj.event === 'edit') {
                        layer.open({
                            type: 1,
                            closeBtn: false,
                            shift: 7,
                            shadeClose: true,
                            title: "修改项目结果信息",
                            btn: ["确认修改","取消修改"],
                            btnAlign: 'c',
                            content:
                                "<div style='width:350px;'><div style='width:320px;margin-left: 3%;' class='form-group has-feedback'><p>请输入检验结果</p><input id='xmcdz' class='form-control' type='text' id='xmcdz' value="+data.xmcdz+"></div>"+
                                "<div style='width:320px;margin-left: 3%;' class='form-group has-feedback'><p>请输项目代号</p><input  class='form-control' type='text' id='xmdh' value="+data.xmdh+"></div>"+
                                "<div style='width:320px;margin-left: 3%;' class='form-group has-feedback'><p>请输入检验高低标记</p><input  class='form-control' type='text' id='gdbj' value="+data.gdbj+"></div>"+
                                "<div style='width:320px;margin-left: 3%;' class='form-group has-feedback'><p>请输入检验参考范围</p><input class='form-control' type='text' id='ckz' value="+data.ckz+"></div>"
                                ,
                            yes: function(index, layero){
                                var url = "EditXmcdzByYxyx";
                                var xmdh= $("#xmdh").val();
                                var gdbj= $("#gdbj").val();
                                var ckz= $("#ckz").val();
                                var xmcdz= $("#xmcdz").val();
                                var data = {'cdrq':cdrq,'ybbh':ybbh,'yqdh':yqdh,'xmdh':xmdh,'xmcdz':xmcdz,'gdbj':gdbj,'ckz':ckz,};
                               /* console.log(data);*/
                                 $.post(url,data,function(result){
                                     layer.load(2);
                                     setTimeout(function(){
                                         layer.closeAll('loading');
                                     }, 1000);
                                     if(result.code == 1) {
                                         layer.msg(result.msg);
                                     }
                                     if(result.status == 0) {
                                         layer.msg(result.msg);
                                     }
                                },'json');
                                table.reload('demo', {});
                                layer.close(index);
                            }
                        });
                    }
                });
                //监听表格复选框选择
                table.on('checkbox(demo)', function (obj) {
                    console.log(obj)
                });
                //头工具栏事件
                table.on('toolbar(demo)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'getCheckData':
                            var data = checkStatus.data;
                            if(data.length < 1){
                                layer.msg('至少选择一个');
                            }else{
                                /*layer.alert(JSON.stringify(data));*/
                                layer.confirm('确认删除选择的数据', function (index) {
                                    layer.load(2);
                                    setTimeout(function(){
                                        layer.closeAll('loading');
                                    }, 150000);
                                    layer.close(index);
                                   var data = JSON.stringify(data);
                                    var url = 'DelXmcdzByYxyxBetween';
                                    $.post(url,data,function(result){
                                        if(result.code == 1) {
                                            layer.msg(result.msg);
                                        }
                                        if(result.status == 0) {
                                            layer.msg(result.msg);
                                        }

                                    },'JSON');
                                    obj.del();
                                    layer.close(index);
                                });
                            }
                            break;
                        case 'getCheckLength':
                            var data = checkStatus.data;
                            table.reload('demo', {})
                            layer.msg('刷新成功');
                            break;
                        case 'isAll':
                            layer.msg(checkStatus.isAll ? '全选' : '未全选');
                            break;
                    }
                    ;
                });
            });

    </script>
    {include file="public/footer"/}